﻿using AnesSystem.Models;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// DrugLineUtilCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class DrugLineContainerCtrl : UserControl
    {

        #region Variables
        private int _currentPage = 1;

        private ObservableCollection<DrugLineBoxCtrl> _drugLineBoxList = new ObservableCollection<DrugLineBoxCtrl>();
        private ObservableCollection<DrugLineBoxCtrl> _drugPacuLineBoxList = new ObservableCollection<DrugLineBoxCtrl>();
        #endregion

        #region Constructor

        public DrugLineContainerCtrl()
        {
            InitializeComponent();
            this.Height = LocationUtil.Medicine_Height;
            this.Loaded += DrugLineContainerCtrl_Loaded;
        }

        #endregion

        #region Properties

        //public int Index { get; set; }

        public int CurrentPage
        {
            get
            {
                return _currentPage;
            }

            set
            {
                _currentPage = value;
            }
        }

        public ObservableCollection<DrugLineBoxCtrl> DrugLineBoxList
        {
            get
            {
                return _drugLineBoxList;
            }

            set
            {
                _drugLineBoxList = value;
            }
        }

        public ObservableCollection<DrugLineBoxCtrl> DrugPacuLineBoxList
        {
            get
            {
                return _drugPacuLineBoxList;
            }

            set
            {
                _drugPacuLineBoxList = value;
            }
        }



        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods


        //private double CaleTop()
        //{
        //    double top = Index * LocationUtil.Medicine_Height;
        //    return top;
        //}

        #endregion

        #region Public/Protected Methods

        #endregion

        #region EventHandlers

        private void DrugLineContainerCtrl_Loaded(object sender, RoutedEventArgs e)
        {

        }

        public void DrawLineContainer()
        {
            List<PatientDrugsModel> list = this.DataContext as List<PatientDrugsModel>;
            DrugLineBoxCtrl ctrl = new DrugLineBoxCtrl();
            double left = CaleLeftWidth(list[0].BeginTime);
            this.Margin = new Thickness(LocationUtil.Medicine_Left_Width, 0, 0, 0);
            ctrl.DataContext = list;
            ctrl.CurrentPage = CurrentPage;
            ctrl.DrawLine();
            DrugLineBoxList.Add(ctrl);
            _wp.Children.Add(ctrl);
        }

        public void DrawLinePacuContainer()
        {
            List<PatientDrugsModel> list = this.DataContext as List<PatientDrugsModel>;
            DrugLineBoxCtrl ctrl = new DrugLineBoxCtrl();
            double left = CalePacuLeftWidth(list[0].BeginTime);
            this.Margin = new Thickness(LocationUtil.Medicine_Left_Width, 0, 0, 0);
            ctrl.DataContext = list;
            ctrl.CurrentPage = CurrentPage;
            ctrl.DrawPacuLine();
            DrugPacuLineBoxList.Add(ctrl);
            _wp.Children.Add(ctrl);
        }


        public virtual double CaleLeftWidth(DateTime time)
        {
            TimeSpan tp = time - DataManager.Instance.CurrentPatientLink.Status.AnesRecordStartTime;
            double minutes = tp.Days * 24 * 60 + tp.Hours * 60 + tp.Minutes;
            double round = (minutes / LocationUtil.SpanMinites) * LocationUtil.RealTimeItem_Width;
            return round;
        }
        public virtual double CalePacuLeftWidth(DateTime time)
        {
            TimeSpan tp = time - DataManager.Instance.CurrentPatientLink.Status.PacuStartTime;
            double minutes = tp.Days * 24 * 60 + tp.Hours * 60 + tp.Minutes;
            double round = (minutes / LocationUtil.SpanMinites) * LocationUtil.RealTimeItem_Width;
            return round;
        }
        #endregion
    }
}
